// pages/market/integralList/integralList.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    list:[
      {
        status: '0',
        id: 9,
        img: 'http://www.meiliancheng.cn/public/meiliancheng/imagezy/banner.png',
        imgUrls: [
          'http://www.meiliancheng.cn/public/meiliancheng/imagezy/banner.png',
          'http://www.meiliancheng.cn/public/meiliancheng/imagezy/banner.png',
          'http://www.meiliancheng.cn/public/meiliancheng/imagezy/banner.png'
        ],
        title: '商品标题商品标题商品标题',
        tips: '商品描述 商品描述',
        price: 34,
        integral: 220,
        nums: 2,
        time:'2018-12-13 09:23:43'
      }, {
        status: '1',
        id: 9,
        img: 'http://www.meiliancheng.cn/public/meiliancheng/imagezy/banner.png',
        imgUrls: [
          'http://www.meiliancheng.cn/public/meiliancheng/imagezy/banner.png',
          'http://www.meiliancheng.cn/public/meiliancheng/imagezy/banner.png',
          'http://www.meiliancheng.cn/public/meiliancheng/imagezy/banner.png'
        ],
        title: '商品标题商品标题商品标题',
        tips: '商品描述 商品描述',
        price: 34,
        integral: 220,
        nums: 2,
        time: '2018-12-13 09:23:43'
      }, {
        status: '0',
        id: 9,
        img: 'http://www.meiliancheng.cn/public/meiliancheng/imagezy/banner.png',
        imgUrls: [
          'http://www.meiliancheng.cn/public/meiliancheng/imagezy/banner.png',
          'http://www.meiliancheng.cn/public/meiliancheng/imagezy/banner.png',
          'http://www.meiliancheng.cn/public/meiliancheng/imagezy/banner.png'
        ],
        title: '商品标题商品标题商品标题',
        tips: '商品描述 商品描述',
        price: 34,
        integral: 220,
        nums: 2,
        time: '2018-12-13 09:23:43'
      }
    ] 
  },
  toget(e){
    var that = this;
    var index = e.currentTarget.dataset.index;
    var id = e.currentTarget.dataset.id;
    console.log(e)
    var product = that.data.product;
    wx.showModal({
      title: '确认领取',
      content: '请在领取人当面点击领取,否则出现问题我们概不负责。',
      confirmText:'领取',
      success(res){
        if(res.confirm){
          wx.request({
            url: app.siteInfo.scoreroot + 'getgoods',
            method: "get",
            data: {
              id: id,
              uid: app.siteInfo.uid,
              pid: app.siteInfo.pid,
              com_part_id: app.siteInfo.com_part_id,
            },
            success: function (res) {
              if(res.data.code == 200){
                product[index].status = 2;
                that.setData({
                  product:product
                })
                wx.showToast({
                  title: '领取成功',
                  icon: 'success',
                })
              }else{
                wx.showToast({
                  title: '领取失败',
                  icon: 'none',
                })
              }
            }
          })
          
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.setNavigationBarTitle({
      title: '兑换列表'//页面标题为路由参数
    })
    wx.request({
      url: app.siteInfo.scoreroot + 'duidetail',
      method: "get",
      data: {
        uid: app.siteInfo.uid,
        pid: app.siteInfo.pid,
        com_part_id: app.siteInfo.com_part_id,
      },
      success: function (res) {
        that.setData({
          product: res.data.list,
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})